<template>
  <view class="container">
    <z-paging-swiper>
      <view slot="top">
        <u-navbar height="50" title="业绩申请" title-size="36" title-color="#333"> </u-navbar>
        <view class="tabsView">
          <u-tabs-swiper
            ref="uTabs"
            :list="tabsList"
            :current="current"
            @change="tabsChange"
            :is-scroll="false"
            :show-bar="false"
            active-color="#0F76BC"
            swiper-width="750"
          >
          </u-tabs-swiper>
        </view>
        <u-gap height="20" bg-color="#F0F1F2"></u-gap>
      </view>
      <swiper
        class="swiperView"
        :current="scurrent"
        @transition="transition"
        @animationfinish="animationfinish"
      >
        <swiper-item v-for="(item2, index2) in tabsList" :key="index2" class="swiperItem">
          <z-paging
            ref="paging"
            v-model="itemList[index2]"
            @query="queryList"
            :fixed="true"
            :auto="false"
            :empty-view-img="`${getImageUrl('empty.png')} `"
            empty-view-text="暂无订单数据~"
            :empty-view-img-style="imgStyle"
          >
            <view class="goodsItemView">
              <view
                class="itemView"
                v-for="(item, index1) in itemList[index2]"
                :key="index1"
                @click="onOrderDetail(item)"
              >
                <view class="order-top">
                  <view class=""> 申请时间：{{ createTime(item.createTime) }} </view>
                  <view v-if="item.auditStatus == 0" class="order-top-tip"> 待审核 </view>
                  <view v-else-if="item.auditStatus == 1" class="order-top-tip"> 已通过 </view>
                  <view v-else-if="item.auditStatus == 2" class="order-top-tip"> 已驳回 </view>
                </view>
                <view v-if="item.auditStatus == 3" class="warning">
                  驳回原因：{{ item.auditReason }}
                </view>

                <view class="order-box">
                  <view class="order-item">
                    <view class="item-title"> 申请原因： </view>
                    <view class="item-content">
                      客户下单忘记填写推荐码，客户下单忘记填写推荐码，客户下单忘记填写推荐码客户下单忘记填写推荐码
                    </view>
                  </view>
                  <view class="order-item">
                    <view class="item-title"> 客户信息： </view>
                    <view class="item-content">
                      {{ item.customerName }}-{{ item.customerMobile }}
                    </view>
                  </view>
                </view>

                <view class="btn-group" v-if="item.auditStatus == 0">
                  <view class="hollow-btn btn" style="background-color: #89ba45; color: #fff">
                    查看详情
                  </view>
                  <view @click.stop.prevent="eidt(item)" class="hollow-btn btn"> 修改信息 </view>
                </view>
                <view class="btn-group" v-else>
                  <view class="hollow-btn btn" style="background-color: #89ba45; color: #fff">
                    查看详情
                  </view>
                </view>
              </view>
            </view>
          </z-paging>
        </swiper-item>
      </swiper>
    </z-paging-swiper>

    <view class="handle-btn-area" style="color: #0f76bc">
      <view class="">
        <view class="handle-btn" @click="routeToApply">
          <u-icon :name="getImageUrl('fbxx.png')" size="48rpx"></u-icon>
        </view>
        <view class=""> 我要申请 </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      imgStyle: {
        width: '12rem'
      },
      current: 0,
      scurrent: 0,
      tabsList: [
        {
          name: '全部',
          status: ''
        },
        {
          name: '待审核',
          status: 0
        },
        {
          name: '已通过',
          status: 1
        },
        {
          name: '已驳回',
          status: 2
        }
      ],
      itemList: [[], [], [], []],

      order_id: ''
    }
  },
  onLoad(res) {
    let self = this
    this.queryList()
  },
  onShow() {
    let self = this
    this.$nextTick(function () {
      //self.onOrderLoad(self.current, null, true);
    })
  },
  computed: {
    createTime() {
      return (e) => this.$utils.parseTime(e)
    }
  },
  methods: {
    tabsChange(index) {
      this.scurrent = index
    },
    transition(e) {
      let dx = e.detail.dx
      this.$refs.uTabs.setDx(dx)
    },
    animationfinish(e) {
      this.current = e.detail.current
      this.scurrent = e.detail.current
      this.$refs.uTabs.setFinishCurrent(e.detail.current)
      if (this.itemList[this.current].length == 0) {
        this.queryList()
      }
    },
    queryList(pageNo = 1, pageSize = 10) {
      this.$u
        .get('/app-api/trade/brokerage-achievement/page', {
          pageNo,
          pageSize,
          auditStatus: this.tabsList[this.current].status
        })
        .then((res) => {
          this.$refs.paging[this.current].complete(res.data.list)
        })
    },

    eidt(item) {
      this.$utils.route({
        url: '/other_center/salesman-performance-apply/salesman-performance-apply',
        params: {
          id: item.id
        }
      })
    },
    onOrderDetail(item) {
      this.$utils.route({
        url: '/other_center/salesman-performance-info/salesman-performance-info',
        params: {
          id: item.id
        }
      })
    },
    routeToApply() {
      uni.navigateTo({
        url: '/other_center/salesman-performance-apply/salesman-performance-apply'
      })
    }
  }
}
</script>

<style>
page {
  height: 100%;
  background: #f0f1f2;
}

.tabsView {
  display: flex;
  flex-direction: column;
  background: #ffffff;
  height: 90rpx;
}

.goodsItemView {
  display: flex;
  flex-direction: column;
}

.itemView {
  display: flex;
  flex-direction: column;
  background-color: #ffffff;
  margin-bottom: 1rem;
  border-radius: 6px;
  padding: 20rpx;
}

.order-top {
  position: relative;
  padding: 15rpx 0;
  font-size: 30rpx;
}

.order-top-tip {
  position: absolute;
  top: 15rpx;
  right: 0;
  color: #999999;
}

.order-box {
  border-top: 2rpx #ededed solid;
  border-bottom: 2rpx #ededed solid;
  margin: 10rpx 0;
}
.order-item {
  display: flex;
  line-height: 55rpx;
}
.item-title {
  flex: 2;
}
.item-content {
  flex: 8;
}

.price-total {
  padding: 20rpx 0;
  border-top: #ededed solid 2rpx;
  border-bottom: #ededed solid 2rpx;
  text-align: right;
  font-size: 28rpx;
  margin: 15rpx 0;
}

.btn-group {
  display: flex;
  flex-direction: row-reverse;
}

.btn {
  display: inline-block;
  padding: 15rpx 20rpx;
  border-radius: 35rpx;
  font-size: 28rpx;
  margin-left: 15rpx;
}
.hollow-btn {
  color: #666666;
  border: #e6e6e6 solid 2rpx;
}
.solid-btn {
  background-color: #0f76bc;
  color: #fff;
}

.warning {
  padding: 20rpx;
  background-color: #fef4f4;
  color: #ff4445;
  font-size: 24rpx;
  overflow: hidden;
  white-space: nowrap; /* 不换行 */
  text-overflow: ellipsis; /* 使用省略号表示被隐藏的部分 */
}

.handle-btn-area {
  position: fixed;
  right: 20rpx;
  bottom: 150rpx;
  z-index: 9999;
  display: flex;
  flex-direction: column;
}

.handle-btn {
  margin-bottom: 20rpx;
  width: 100rpx;
  height: 100rpx;
  background-color: #0f76bc;
  border-radius: 100rpx;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
